package com.service.imp;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;

import jxl.Workbook;
import jxl.format.UnderlineStyle;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dao.AssetsClassDao;
import com.dao.StaffDao;
import com.dao.UserDao;
import com.model.AssetsClassBean;
import com.model.Messages;
/**
 * 这里service 集合了所有树结构的存取
 * @author lenove-x
 *
 */
@Service
@Transactional(rollbackFor = { RuntimeException.class }, propagation = Propagation.REQUIRED)
public class TreeService {
	@Autowired
	private UserDao userDao;
	@Autowired
	private JdbcTemplate jdbcTemplate;
	@Autowired
	private AssetsClassDao assetsClassDao;
	@Autowired
	private StaffDao staffDao;
	
	/**
	 * 获取部门的树
	 * @return
	 */
	public List<Map<String, Object>> getDeptTree() {
		List<Map<String,Object>> alllist = new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> alllist2=new ArrayList<Map<String,Object>>();
	
	
		StringBuffer sb= new StringBuffer();
		sb.append("select a.id");
		sb.append(",a.dept_name");
		sb.append(",a.isParent,a.dept_pid");
		sb.append(" from tb_dept a");

		System.out.println(sb.toString());
		alllist=this.jdbcTemplate.queryForList(sb.toString());
		//将大写转换小写
		Map<String, Object> treeNode =null;
		for(Map<String,Object> m:alllist){
			treeNode = new HashMap<String, Object>();
			treeNode.put("id",m.get("id"));
			treeNode.put("name", m.get("dept_name"));
			treeNode.put("pId", m.get("dept_pid"));
			
			if(m.get("id").toString().equals("-100")){
				treeNode.put("open", true);
				treeNode.put("iconSkin", "icon-home");
			}else
				treeNode.put("iconSkin","icon-group");
			alllist2.add(treeNode);
		}
		return alllist2;
	}
	
	/*
	 *else{
			StringBuffer sb2= new StringBuffer();
			sb2.append("select a.*");
			sb2.append(" from tb_staff a where a.staff_salary=0 and a.dept_id=");
			sb2.append(dept_id);
			alllist=this.jdbcTemplate.queryForList(sb2.toString());
			for(Map<String,Object> m:alllist){
				treeNode = new HashMap<String, Object>();
				//这里
				treeNode.put("id",m.get("id").hashCode());
				treeNode.put("name", m.get("staff_number"));
				treeNode.put("pId", m.get("dept_id"));
				treeNode.put("isParent", false);
				treeNode.put("staff_sex", m.get("staff_sex"));
				treeNode.put("staff_eb", m.get("staff_eb"));
				treeNode.put("staff_phone", m.get("staff_phone"));
				treeNode.put("staff_address", m.get("staff_address"));
				treeNode.put("staff_post", m.get("staff_post"));
				treeNode.put("staff_id_card", m.get("staff_id_card"));
				treeNode.put("staff_hire", m.get("staff_hire"));
				treeNode.put("staff_date_birth", m.get("staff_date_birth"));
				treeNode.put("staff_salary", m.get("staff_salary"));
				treeNode.put("staff_number", m.get("staff_number"));
				treeNode.put("iconSkin"," icon-user");
				alllist2.add(treeNode);
			}
		} 
	 */
	/**
	 * 获取资产分类树
	 * @return
	 */
	
	public List<Map<String, Object>> getAssetsclassTree() {
		StringBuffer sb= new StringBuffer();
		sb.append("select a.ac_id");
		sb.append(",a.ac_name");
		sb.append(",a.isparent,a.ac_pid,a.ac_coding");
		sb.append(" from tb_assets_class a");

		List<Map<String,Object>> alllist=this.jdbcTemplate.queryForList(sb.toString());
		List<Map<String,Object>> alllist2=new ArrayList<Map<String,Object>>();
		Map<String, Object> treeNode =null;
		for(Map<String,Object> m:alllist){
			treeNode = new HashMap<String, Object>();
			treeNode.put("id",m.get("ac_id"));
			treeNode.put("name", m.get("ac_name"));
			treeNode.put("pId", m.get("ac_pid"));
			treeNode.put("isParent", m.get("isparent").toString().equals("1"));
			treeNode.put("coding", m.get("ac_coding"));
			if(m.get("ac_id").toString().equals("0"))
				treeNode.put("open", true);
			alllist2.add(treeNode);
		}
		
		return alllist2;
	}

	@SuppressWarnings("deprecation")
	public Messages addAssetsclass(AssetsClassBean ac) {
		Messages m= new Messages();
		if(ac.getAc_name()!=null&&!"".equals(ac.getAc_name())&&ac.getAc_pid()!=null){
			//取当前节点父节点下 最大的子节点编号
			String sql="select max(t.ac_id) from tb_assets_class t where t.ac_pid="+ac.getAc_pid();
			int maxId=0;
			
			try {
				maxId=this.jdbcTemplate.queryForInt(sql);
				
				if(maxId==0){
					sql="update tb_assets_class t set t.isparent=1 where t.ac_pid="+ac.getAc_pid();
					this.jdbcTemplate.update(sql);
					maxId=ac.getAc_pid()*100;
				}
			} catch (Exception e) {//如果出现异常，说明这个节点不是父节点，则修改节点
				System.out.println(e.getMessage());
				sql="update tb_assets_class t set t.isparent=1 where t.ac_id="+ac.getAc_pid();
				this.jdbcTemplate.update(sql);
				maxId=ac.getAc_pid()*100;
			}
		
			ac.setAc_id(maxId+1);
			ac.setIsParent(false);
			//ac.setLevelnum(levelnum);
//			System.out.println("name:"+ac.getAc_name());
//			System.out.println("编号："+ac.getAc_coding());
//			System.out.println("id："+ac.getAc_id());
//			System.out.println("pid："+ac.getAc_pid());
//			System.out.println("层级："+ac.getLevelnum());
			
			this.assetsClassDao.save(ac);
			m.setInfo(true);
			m.setText("增加节点成功");
		}else{
			m.setInfo(false);
			m.setText("名称或父节点不可为空");
		}
		return m;
	}

	@SuppressWarnings("deprecation")
	public Messages editAssetsclass(AssetsClassBean ac) {
		Messages m= new Messages();
		AssetsClassBean assetssBean= this.assetsClassDao.get(ac.getAc_id());
		if(ac.getAc_name()!=null&&!"".equals(ac.getAc_name())&&ac.getAc_pid()!=null){
			assetssBean.setAc_coding(ac.getAc_coding());
			assetssBean.setAc_name(ac.getAc_name());
			//判断是否有修改父节点 不相等 修改当前节点的 层级
			if(!assetssBean.getAc_pid().equals(ac.getAc_pid())){
				assetssBean.setAc_pid(ac.getAc_pid());
				String sql = "select a.levelnum from tb_assets_class a where a.ac_id="+ac.getAc_pid();
				int level = this.jdbcTemplate.queryForInt(sql);
				assetssBean.setLevelnum(level+1);
			}
			this.assetsClassDao.update(assetssBean);
			m.setInfo(true);
			m.setText("修改成功");
		}else{
			m.setInfo(false);
			m.setText("名称或父节点不可为空");
		}
		return m;
	}
	/**
	 * 删除叶子节点
	 * @param id
	 * @return
	 */
	public Messages delAssetsclass(String id) {
		Messages m= new Messages();
		if(id!=null&&!"".equals(id)){
			this.delAssetsclassisParent(id);
			m.setInfo(true);
			m.setText("删除成功");
		}else{
			m.setInfo(false);
			m.setText("删除节点出错，节点id 不可为空");
		}
		return m;
	}
	public void delAssetsclassisParent(String id){
		this.assetsClassDao.delete(this.assetsClassDao.get(Integer.parseInt(id)));
		String sql ="select t.ac_id from tb_assets_class t where t.ac_pid="+id;
		List<Map<String,Object>> l= this.jdbcTemplate.queryForList(sql);
		if(!l.isEmpty()){
			for(Map<String,Object> map:l){
				this.delAssetsclassisParent(map.get("ac_id").toString());
			}
		}
		
	}
	
	public InputStream getAccetsclassDate() throws Exception {
		WritableWorkbook wwb = null;
		ServletContext rel = ServletActionContext.getServletContext();
		String uploadPath = rel.getRealPath("/uploadfiles");
		File f= new File(uploadPath + "/" + "资产分类.xls");
		try {// 首先要使用Workbook类的工厂方法创建一个可写入的工作薄(Workbook)对象
			wwb = Workbook.createWorkbook(f);

			String sql ="select t.* from tb_assets_class t order by to_char(t.ac_id) asc";
			List<Map<String,Object>> l= this.jdbcTemplate.queryForList(sql);
			if (wwb != null) {
				WritableSheet ws = wwb.createSheet("sheet1", 0);//创建新工作薄
				//设置标题
				Label labelC1 = new Label(0, 0,"ID");
				Label labelC2 = new Label(1, 0, "编号");
				Label labelC3 = new Label(2, 0, "名称");
				Label labelC4 = new Label(3, 0, "父ID");
				Label labelC5 = new Label(4, 0, "是否父节点");
				Label labelC6 = new Label(5, 0, "层级");
				
	//			logger.info("正在写入标题");
				ws.addCell(labelC1);
				ws.addCell(labelC2);
				ws.addCell(labelC3);
				ws.addCell(labelC4);
				ws.addCell(labelC5);
				ws.addCell(labelC6);
				Map<String,Object> map;
				for (int i = 0; i < l.size(); i++) {
					map=l.get(i);
					labelC1 = new Label(0, i+1 ,map.get("ac_id").toString());
					labelC2 = new Label(1, i+1 ,map.get("ac_coding").toString());
					labelC3 = new Label(2, i+1 ,map.get("ac_name").toString());
					labelC4 = new Label(3, i+1 ,map.get("ac_pid").toString());
					labelC5 = new Label(4, i+1 ,map.get("isParent").toString());
					labelC6 = new Label(5, i+1 ,map.get("levelnum").toString());
	//				logger.info("正在写入第" + i + "条");
					ws.addCell(labelC1);
					ws.addCell(labelC2);
					ws.addCell(labelC3);
					ws.addCell(labelC4);
					ws.addCell(labelC5);
					ws.addCell(labelC6);
				}
					// 从内存中写入文件中
				wwb.write();
				// 关闭资源，释放内存
				wwb.close();
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new FileInputStream(f);
	}

	public InputStream getDeptDate() throws FileNotFoundException {
		WritableWorkbook wwb = null;
		ServletContext rel = ServletActionContext.getServletContext();
		String uploadPath = rel.getRealPath("/uploadfiles");
		File f= new File(uploadPath + "/" + "部门员工.xls");
		try {// 首先要使用Workbook类的工厂方法创建一个可写入的工作薄(Workbook)对象
			wwb = Workbook.createWorkbook(f);
		
	//		logger.info("准备写入文件：" );
			String sql ="select t.*,d.dept_name from tb_staff t left join tb_dept d on t.dept_id=d.id order by t.staff_number asc";
			List<Map<String,Object>> l= this.jdbcTemplate.queryForList(sql);
			DecimalFormat df1=new DecimalFormat("#.00");
			if (wwb != null) {
				WritableSheet ws = wwb.createSheet("sheet1", 0);//创建新工作薄
				//设置标题
				Label labelC1 = new Label(0, 0,"编号");
				Label labelC2 = new Label(1, 0, "姓名");
				Label labelC3 = new Label(2, 0, "性别");
				Label labelC4 = new Label(3, 0, "学历");
				Label labelC5 = new Label(4, 0, "电话");
				Label labelC6 = new Label(5, 0, "住址");
				Label labelC7 = new Label(6, 0, "出生日期");
				Label labelC8 = new Label(7, 0, "部门");
				Label labelC9 = new Label(8, 0, "职务");
				Label labelC10 = new Label(9, 0, "薪水");
				Label labelC11 = new Label(10, 0, "身份证");
				Label labelC12 = new Label(11, 0, "录用时间");
				
	//			logger.info("正在写入标题");
				ws.addCell(labelC1);
				ws.addCell(labelC2);
				ws.addCell(labelC3);
				ws.addCell(labelC4);
				ws.addCell(labelC5);
				ws.addCell(labelC6);
				ws.addCell(labelC7);
				ws.addCell(labelC8);
				ws.addCell(labelC9);
				ws.addCell(labelC10);
				ws.addCell(labelC11);
				ws.addCell(labelC12);
				Map<String,Object> map;
				for (int i = 0; i < l.size(); i++) {
					map=l.get(i);
					labelC1 = 	new Label(0, i+1, map.get("staff_number")==null?"":map.get("staff_number").toString());
					labelC2 = 	new Label(1, i+1, map.get("staff_name")==null?"":map.get("staff_name").toString());
					labelC3 = 	new Label(2, i+1, map.get("staff_sex")==null?"": map.get("staff_sex").toString());
					labelC4 = 	new Label(3, i+1, map.get("staff_eb")==null?"":map.get("staff_eb").toString());
					labelC5 = 	new Label(4, i+1, map.get("staff_phone")==null?"":map.get("staff_phone").toString());
					labelC6 = 	new Label(5, i+1, map.get("staff_address")==null?"":map.get("staff_address").toString());
					labelC7 = 	new Label(6, i+1, map.get("staff_date_birth")==null?"": map.get("staff_date_birth").toString());
					labelC8 = 	new Label(7, i+1, map.get("dept_name")==null?"":map.get("dept_name").toString());
					labelC9 = 	new Label(8, i+1, map.get("staff_post")==null?"":map.get("staff_post").toString());
					labelC10 = 	new Label(9, i+1, map.get("staff_salary")==null?"0.00￥":df1.format(Double.parseDouble(map.get("staff_salary").toString())));
					labelC11 = 	new Label(10,i+1, map.get("staff_id_card")==null?"":map.get("staff_id_card").toString());
					labelC12 = 	new Label(11,i+1, map.get("staff_hire")==null?"":map.get("staff_hire").toString());
	//				logger.info("正在写入第" + i + "条");
					ws.addCell(labelC1);
					ws.addCell(labelC2);
					ws.addCell(labelC3);
					ws.addCell(labelC4);
					ws.addCell(labelC5);
					ws.addCell(labelC6);
					ws.addCell(labelC7);
					ws.addCell(labelC8);
					ws.addCell(labelC9);
					ws.addCell(labelC10);
					ws.addCell(labelC11);
					ws.addCell(labelC12);
				}
					// 从内存中写入文件中
				wwb.write();
				// 关闭资源，释放内存
				wwb.close();
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new FileInputStream(f);
	}
	/**
	 * 获取资产存放地点树
	 */
	public List<Map<String,Object>> getMeasureTreeBytype(String type){
		List<Map<String, Object>> list=new ArrayList<Map<String,Object>>();
		Map<String,Object> map= new HashMap<String, Object>();
		map = new HashMap<String, Object>();
		map.put("id",-99);
		map.put("name", type);
		map.put("pId", -101);
		map.put("isParent", true);
		list.add(map);
		StringBuffer sb= new StringBuffer();
		sb.append("select a.measure_id");
		sb.append(",a.measure_name");
		sb.append(" from tb_basis_measure a where 1=1");
		sb.append(" and a.measure_type='");
		sb.append(type);
		sb.append("'");
		
		for(Map<String,Object> m:this.jdbcTemplate.queryForList(sb.toString())){
			map= new HashMap<String, Object>();
			map.put("id",(type.hashCode()+Integer.parseInt(m.get("measure_id").toString())));
			map.put("name", m.get("measure_name"));
			map.put("pId", -99);
			list.add(map);
		}
		
		return list;
	}
	/**
	 * 获取全部树集合
	 * @return
	 */
	public List<Map<String, Object>> getALLTree() {
		List<Map<String, Object>> all= new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> list=this.getDeptTree();
		for(Map<String,Object> map:list){
			map.put("fieldName", "a_use_dept");
			map.put("field", map.get("id"));
		}
		all.addAll(list);
		list =this.getAssetsclassTree();
		for(Map<String,Object> map:list){
			map.put("fieldName", "a_class_name");
			map.put("field", map.get("name"));
		}
		all.addAll(list);
		list =this.getMeasureTreeBytype("存放地点");
		for(Map<String,Object> map:list){
			map.put("fieldName", "a_store");
			map.put("field", map.get("name"));
		}
		all.addAll(list);
		return all;
	}
	/**
	 * 部门三栏
	 * @param list 需要写入的集合
	 * @return
	 * @throws Exception
	 */
	public InputStream getDowndeptThree(List<Map<String, Object>> list) throws Exception {
		WritableWorkbook wwb = null;
		ServletContext rel = ServletActionContext.getServletContext();
		String uploadPath = rel.getRealPath("/uploadfiles");
		File f= new File(uploadPath + "/" + "temp.xls");
		try {// 首先要使用Workbook类的工厂方法创建一个可写入的工作薄(Workbook)对象
			wwb = Workbook.createWorkbook(f);
		
	//		logger.info("准备写入文件：" );
			
			DecimalFormat df1=new DecimalFormat("###,###.00");
			if (wwb != null) {
				WritableSheet ws = wwb.createSheet("sheet1", 0);//创建新工作薄
				WritableCellFormat cellFormat = new WritableCellFormat();
				cellFormat.setAlignment(jxl.format.Alignment.CENTRE); 
				//设置标题
				Label labelC1 = new Label(0, 0,"部门名称");
				labelC1.setCellFormat(cellFormat);
				Label labelC2 = new Label(1, 0, "月初");
				labelC2.setCellFormat(cellFormat);
				
				Label labelC3 = new Label(1, 1, "数量");
				Label labelC4 = new Label(2, 1, "金额");
				
				Label labelhead3 = new Label(3, 0, "增加");
				labelhead3.setCellFormat(cellFormat);
				Label labelC5 = new Label(3, 1, "数量");
				Label labelC6 = new Label(4, 1, "金额");
				
				Label labelhead5 = new Label(5, 0, "减少");
				labelhead5.setCellFormat(cellFormat);
				Label labelC7 = new Label(5, 1, "数量");
				Label labelC8 = new Label(6, 1, "金额");
				
				Label labelhead7 = new Label(7, 0, "月末");
				labelhead7.setCellFormat(cellFormat);
				Label labelC9 = new Label(7, 1, "数量");
				Label labelC10 = new Label(8, 1, "金额");
				
	//			logger.info("正在写入标题");
				ws.addCell(labelC1);
				ws.addCell(labelC2);
				ws.addCell(labelC3);
				ws.addCell(labelC4);
				ws.addCell(labelC5);
				ws.addCell(labelC6);
				ws.addCell(labelC7);
				ws.addCell(labelC8);
				ws.addCell(labelC9);
				ws.addCell(labelC10);
				ws.addCell(labelhead3);
				ws.addCell(labelhead5);
				ws.addCell(labelhead7);
				ws.mergeCells(0, 0,0, 1);
				ws.mergeCells(1, 0, 2, 0);
				ws.mergeCells(3, 0, 4, 0);
				ws.mergeCells(5, 0, 6, 0);
				ws.mergeCells(7, 0, 8, 0);
				Map<String,Object> map;
				for (int i = 0; i < list.size(); i++) {
					map=list.get(i);
					labelC1 = 	new Label(0, i+2, map.get("dept_name").toString());
					labelC2 = 	new Label(1, i+2, map.get("early_number").toString());
					labelC3 = 	new Label(2, i+2, df1.format(map.get("early_money")));
					labelC4 = 	new Label(3, i+2, map.get("add_number").toString());
					labelC5 = 	new Label(4, i+2, df1.format(map.get("add_money")));
					labelC6 = 	new Label(5, i+2, map.get("dec_number").toString());
					labelC7 = 	new Label(6, i+2, df1.format(map.get("dec_money")));
					labelC8 = 	new Label(7, i+2, map.get("end_number").toString());
					labelC9 = 	new Label(8, i+2, df1.format(map.get("end_money")));
	//				logger.info("正在写入第" + i + "条");
					ws.addCell(labelC1);
					ws.addCell(labelC2);
					ws.addCell(labelC3);
					ws.addCell(labelC4);
					ws.addCell(labelC5);
					ws.addCell(labelC6);
					ws.addCell(labelC7);
					ws.addCell(labelC8);
					ws.addCell(labelC9);
				}
					// 从内存中写入文件中
				wwb.write();
				// 关闭资源，释放内存
				wwb.close();
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new FileInputStream(f);
	}

	public InputStream getDownd(List<Map<String, Object>> list,String type) throws Exception{
		WritableWorkbook wwb = null;
		ServletContext rel = ServletActionContext.getServletContext();
		String uploadPath = rel.getRealPath("/uploadfiles");
		File f= new File(uploadPath + "/" + "temp.xls");
		try {// 首先要使用Workbook类的工厂方法创建一个可写入的工作薄(Workbook)对象
			wwb = Workbook.createWorkbook(f);
		
	//		logger.info("准备写入文件：" );
			
			DecimalFormat df1=new DecimalFormat("###,###.00");
			if (wwb != null) {
				WritableSheet ws = wwb.createSheet("sheet1", 0);//创建新工作薄
				WritableCellFormat cellFormat = new WritableCellFormat();
				cellFormat.setAlignment(jxl.format.Alignment.CENTRE); 
				//设置标题
				Label labelC1 = new Label(0, 0,type.equals("dept_name")?"部门名称":"资产类别");
				labelC1.setCellFormat(cellFormat);
				Label labelC2 = new Label(1, 0, "合计");
				labelC2.setCellFormat(cellFormat);
				
				Label labelC3 = new Label(1, 1, "资产数量");
				Label labelC4 = new Label(2, 1, "资产价值");
				
				Label labelC5 = new Label(3, 1, "月折旧额");
				Label labelC6 = new Label(4, 1, "累计折旧");
				Label labelC7 = new Label(4, 1, "账面净值");
				
				
	//			logger.info("正在写入标题");
				ws.addCell(labelC1);
				ws.addCell(labelC2);
				ws.addCell(labelC3);
				ws.addCell(labelC4);
				ws.addCell(labelC5);
				ws.addCell(labelC6);
				ws.addCell(labelC7);
				ws.mergeCells(0, 0,0, 1);
				ws.mergeCells(1, 0, 6, 0);

				Map<String,Object> map;
				for (int i = 0; i < list.size(); i++) {
					map=list.get(i);
					labelC1 = 	new Label(0, i+2, map.get(type).toString());
					labelC2 = 	new Label(1, i+2, map.get("amount")==null?"":map.get("amount").toString());
					labelC3 = 	new Label(2, i+2, map.get("total_price")==null?"":df1.format(map.get("total_price")));
					labelC4 = 	new Label(3, i+2, map.get("yzd")==null?"":df1.format(map.get("yzd")));
					labelC5 = 	new Label(4, i+2, map.get("count_d")==null?"":df1.format(map.get("count_d")));
					labelC6 = 	new Label(5, i+2, map.get("jz")==null?"":df1.format(map.get("jz")));

	//				logger.info("正在写入第" + i + "条");
					ws.addCell(labelC1);
					ws.addCell(labelC2);
					ws.addCell(labelC3);
					ws.addCell(labelC4);
					ws.addCell(labelC5);
					ws.addCell(labelC6);
				}
					// 从内存中写入文件中
				wwb.write();
				// 关闭资源，释放内存
				wwb.close();
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new FileInputStream(f);
	}

	public InputStream getDownclassd(List<Map<String, Object>> list) throws Exception{
		// TODO Auto-generated method stub
		return null;
	}


	public static void writeExcel(OutputStream os )throws Exception {  
	    try   {  
	    	File f= new File("D:/temp.xls");
	        jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(f);  
	        //                jxl.write.WritableSheet ws = wwb.createSheet("TestSheet1", 0);  
	        jxl.write.WritableSheet ws = wwb.createSheet("testsheet1", 0);  
	        jxl.write.Label labelC = new jxl.write.Label(0, 0, "我爱中国");  
	        ws.addCell(labelC);  
	        labelC = new jxl.write.Label(1, 2, "我爱中国1,2");  
	        ws.addCell(labelC);  
	  
	        jxl.write.WritableFont wfc = new jxl.write.WritableFont(WritableFont.ARIAL, 20,  
	        WritableFont.BOLD, false,  
	        UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.GREEN);  
	        jxl.write.WritableCellFormat wcfFc = new jxl.write.WritableCellFormat(wfc);  
	        labelC = new jxl.write.Label(6, 0, "中国我爱", wcfFc);  
	        ws.addCell(labelC);  
	        WritableFont wf_merge = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD,  
	        false, UnderlineStyle.DOUBLE_ACCOUNTING, jxl.format.Colour.GREEN);  
	        WritableCellFormat wff_merge = new WritableCellFormat(wf_merge);  
	        // wff_merge.setBackground(jxl.format.Colour.BLACK);  
	        jxl.write.Label label30 = new Label(3, 0, "Label30", wff_merge);  
	        ws.addCell(label30);  
	        //合并单元格  
	        ws.mergeCells(3, 0, 4, 0);  
	        jxl.write.Label label1 = new jxl.write.Label(0, 5, "aaaaa国");  
	        ws.addCell(label1);  
	       // ws.mergeCells(0, 0,0, 1);
			//ws.mergeCells(1, 0, 6, 0);
	  
	        wwb.write();  
	        wwb.close();  
	  
	    }  
	    catch (Exception e )  {  
	        throw e;  
	    }  
	}
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		//System.out.println("402881e64d3d0cf6014d3d0cfa8f0000".hashCode());
		ApplicationContext context = new ClassPathXmlApplicationContext(
				"applicationContext.xml");
		TreeService treetService = (TreeService) context.getBean("treeService");
		try {
			treetService.getALLTree();
			
			//writeExcel(null);
			//DecimalFormat df1=new DecimalFormat("###,###.00");
			//System.out.println(df1.format("23164654"));
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
}
